﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using YY.Admin.ViewModels;
using MenuItem = YY.Admin.ViewModels.MenuItem;
using HandyControl.Controls;
using Window = HandyControl.Controls.Window;
namespace YY.Admin.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void TreeViewItem_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (sender is TreeViewItem item && item.DataContext is MenuItem menuItem)
            {
                var viewModel = DataContext as MainViewModel;
                viewModel?.NavigateCommand.Execute(menuItem);
            }
        }

        private void UserMenuButton_Click(object sender, RoutedEventArgs e)
        {
            if (sender is Button button && button.ContextMenu != null)
            {
                button.ContextMenu.PlacementTarget = button;
                button.ContextMenu.IsOpen = true;
            }
        }

        private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            if (e.NewValue is MenuItem menuItem)
            {
                var viewModel = DataContext as MainViewModel;
                viewModel?.NavigateCommand.Execute(menuItem);
            }
        }
    }
}